// 分页
var page = new Controller.PageControl();
page.init({
    totalCount: 100, 
    conter: ".shop-pagination",
    nowPage: 1
});
// 换开发票页面表单单选
$(".shop-change-invoice-form").on("click", ".shop-form-item", function () {
    $(this).parents("div").eq(0).find(".shop-form-item").removeClass("shop-item-s");
    $(this).addClass("shop-item-s");
    hideTaxpayerCode();
});

// 换开发票页面输入
function formItemInput(a, b) { 
    a.on("focus", function () {
        if ($(this).val() == b) {
            $(this).val("")
        } 
    });
    a.on("focusout", function () {
        if ($(this).val() == "") {
            $(this).val(b)
        }
    });
    
}

formItemInput($(".shop-invoice-title .shop-invoice-title-top input"), "请填写个人发票抬头");
formItemInput($(".shop-invoice-title .shop-invoice-title-bottom input"), "请填写公司发票抬头");


// 判断是否隐藏纳税人识别码
function hideTaxpayerCode(a){
    if( $(".shop-item-s").parents(".shop-invoice-title-bottom").length == 1){
        $(".shop-taxpayer-identification-code").css("display", "block")
    }else{
        $(".shop-taxpayer-identification-code").css("display", "none")
    } 
}


// 手机验证
function phoneVerification(a) {
    if (/^1[34578]\d{9}$/.test(a)) {
        return true
    }
    return false
}
// 增票资质页面input输入
$(".shop-increase-invoice-qualifications-form").on("focus", ".shop-increase-invoice-qualifications-form input", function () {
    if ($(this).val() == ["请输入单位名称", "请输入纳税人识别码", "请输入详细注册地址", "请输入注册电话", "请输入开户银行", "请输入银行账户"][$(this).parents(".shop-item").index()]) {
        $(this).val("").addClass("shop-input-yes");
    }
});
$(".shop-increase-invoice-qualifications-form").on("focusout", ".shop-increase-invoice-qualifications-form input", function () {
    if ($(this).val() == "") {
        $(this).val(["请输入单位名称", "请输入纳税人识别码", "请输入详细注册地址", "请输入注册电话", "请输入开户银行", "请输入银行账户"][$(this).parents(".shop-item").index()]).removeClass("shop-input-yes");
    }
});

// 我的发票发票全选

$(".shop-main").on("click", ".shop-invoice-all", function () {
    if($(this).attr("checked") == "checked"){
        updateinvoice(true)
    }else{
        updateinvoice(false)
    }
    updateStatus()
});

//更改所有发票选中状态
function updateinvoice(a) {
    $(".shop-invoice-item").each(function () {
        $(this).attr("checked", a)
    });
}

// 更新发票全选状态
function updateStatus() {
    $(".shop-invoice-all").attr("checked", "checked")
    $(".shop-invoice-item").each(function () {
        if ($(this).attr("checked") != "checked") {
            $(".shop-invoice-all").attr("checked", false);
        }
    });
} 

$(".shop-invoice-item").on("click", function(){
    updateStatus();
});
